<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>角色管理</title>
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/easyui/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/easyui/themes/icon.css" />
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/cms.css" />

	<script type="text/javascript" src="<%=request.getContextPath() %>/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/easyui/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/js/win.js"></script>
	<script type="text/javascript">
		var rid = 0;
	
		function addRole(){
			openUrl("新增角色", 400, 300, "<%=request.getContextPath() %>/role/initEdit.do");
		}
		
		function reloadDg(){
			$("#dg").datagrid("reload");
			closeWin();
		}
		
		function deleteRole(){
			checkSelectSomeDoAction("#dg", "删除", "角色", "<%=request.getContextPath() %>/role/deleteRoles.do", true);
		}
		
		function editRole(){
			selectOneOpenUrl("#dg","<%=request.getContextPath() %>/role/initEdit.do", 400, 300, "修改", "角色");
		}
		
		function initColumnTree(){
			$("#authColumnTree").tree({
				"url":"<%=request.getContextPath()%>/column/columnTree.do?type=2",
				"checkbox":true
			});
		}
		
		function getRoleColumns(roleId){
			rid = roleId;
			unchecks();
			$.getJSON("<%=request.getContextPath()%>/role/roleColumnIds.do?roleId="+roleId, function(data){
				for(var i = 0; i < data.length; i++){
					var n = $("#authColumnTree").tree("find", data[i]);
					$("#authColumnTree").tree("check", n.target);
				}
			});
		}
		
		function unchecks(){
			var roots = $("#authColumnTree").tree("getRoots");
			for(var i = 0; i < roots.length; i++){
				$("#authColumnTree").tree("uncheck", roots[i].target);
			}
		}
		
		$(function(){
			initColumnTree();
		});
		
		function saveRoleColumn(){
			var nodes = $("#authColumnTree").tree("getChecked");
			var ids = [];
			for(var i = 0; i < nodes.length; i++){
				ids.push(nodes[i].id);
			}
			if(rid != 0){
				$.post("<%=request.getContextPath()%>/role/addRoleColumns.do", {ids:ids.join(","), roleId:rid}, function(msg){
					if(msg == "success"){
						$.messager.alert('提示', '<br />保存成功!', 'info');
					}
				});
			} else {
				$.messager.alert('提示','<br />请先点击角色栏目!', 'warning');
			}
		}
	</script>
</head>
<body  class="easyui-layout">
<div data-options="region:'center',border:false">
	<div class="dg-content">
		<table id="dg" class="easyui-datagrid" title="角色列表"
			data-options="rownumbers:true,fitColumns:true,iconCls:'icon-users',
				toolbar:'#toolbar',url:'<%=request.getContextPath() %>/role/list.do'">
			<thead>
				<tr>
					<th data-options="field:'ck',checkbox:true"></th>
					<th data-options="field:'id',hidden:true"></th>
					<th data-options="field:'name',width:100,align:'center'">名称</th>
					<th data-options="field:'remark',width:150,align:'center'">备注</th>
					<th data-options="field:'opt',width:80,align:'center'">操作</th>
				</tr>
			</thead>
		</table>
		<div class='dg-toolbar' id="toolbar" style="padding:5px 10px;">
			<a href="javascript:addRole()" class="easyui-linkbutton" iconCls="icon-add" plain="true">新增</a>
			<a href="javascript:editRole()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
			<a href="javascript:deleteRole()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
		</div>
	</div>
</div>
<div data-options="region:'east',border:false" style="width:180px;padding: 10px;background-color:#EEE;border-left: 1px solid #DDD">
	<ul id="authColumnTree" style="padding-bottom: 10px"></ul>
	<a href="javascript:saveRoleColumn()" class="easyui-linkbutton" iconCls="icon-save">保存</a>
</div>
</body>
</html>